/**
 * 		XMLSettings.java
 *  Adrián E. Córdoba 		16/06/2013
 */
package ar.com.adriancordoba.app.common.settings;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/**
 * @author Adrián E. Córdoba
 */
public class XMLSettings extends Settings {

	public XMLSettings() {
		setFilename("settings.xml");
		loadSettings();
	}

	@Override
	protected void loadSettings() {
		try {
			InputStream inputStream = new FileInputStream(getFilename());
			Properties properties = new Properties();
			properties.loadFromXML(inputStream);
			setProperties(properties);
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}

	@Override
	protected void saveSettings() {
		try {
			OutputStream outputStream = new FileOutputStream(getFilename());
			getProperties().storeToXML(
					outputStream,
					getFilename().substring(0, getFilename().indexOf('.'))
							+ " Settings");
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}
}
